package main

import "fmt"

func main() {
	var nums []int
	nums = []int{100, 4, 200, 1, 3, 2}
	nums = []int{0, 3, 7, 2, 5, 8, 4, 6, 0, 1}

	v := longestConsecutive(nums)
	fmt.Println(v)
}

func longestConsecutive(nums []int) int {
	numMap := make(map[int]bool, len(nums))
	for _, v := range nums {
		numMap[v] = true
	}

	ans := 0
	// 每个数字只计算比自己大的
	for v, _ := range numMap {
		if numMap[v-1] {
			continue
		}
		ansTmp := 0
		tmpVal := v
		for numMap[tmpVal] {
			tmpVal++
			ansTmp++
		}
		ans = max128(ans, ansTmp)
	}
	return ans
}

func max128(v1, v2 int) int {
	if v1 > v2 {
		return v1
	}
	return v2
}
